  var app = getApp();
  const home_config = require('../../utils/util.js').home_config; 
  Page({
    /**
     * 页面的初始数据
     */
    data: {
      topMain: true,     // 搜索条件
      Search: false,   // 只显示搜索框
      searchMain: true,  //显示列表内容
      showKeyDel: "none",
      keyValue: "",
      parentList: [],
      bussinessInfoList: new Array(),
      searchBusInfoList: new Array(),
      selectConditionList: [
        { id: 1, name: "90#", slt:true },
        { id: 2, name: "93#", slt: false },
        // { id: 3, name: "95#", slt: false },
        { id: 4, name: "97#",slt: false }
      ],
      tipmsg: '按种类',
      tipmsgImg: 'nameSort.png', 
      chooseCondition: false,
      firstName: '京',
      prov: '北京'
    },
    onLoad: function (options) {
      this.requestData();
      // this.sortByname();
    },
    requestData: function () {
      var _this = this;
      wx.request({
        url: home_config ,
        data: {
          showapi_appid: '52654',
          showapi_sign: 'da10562621f84bbbb7aae03e59838e44',
          // prov: '上海'
        },
        method: 'GET',
        success: function (res) {
          console.log(res.data.showapi_res_body.list);
          _this.setData({
            parentList: res.data.showapi_res_body.list
          })
        }
      })
      this.toFirstName();
    },
    // 省份简称
    toFirstName: function() {
      var fName ;
      var parentList_prov = [];
      var parentList_ul = this.data.parentList;
      for (var i = 0; i < parentList_ul.length; i++) {
        // parentList_prov[i] = parentList_ul[i].prov
        parentList_prov.push(parentList_ul[i].prov)
        console.log(parentList_prov);
      }
      console.log(this.data.parentList);

      if (this.prov == '北京') {
        fName = "京";
      } else if (this.prov == "天津") {
        fName = "津";
      } else if (this.prov == "重庆") {
        fName = "渝";
      } else if (this.prov == "上海") {
        fName = "沪";
      } else if (this.prov == "河北") {
        fName = "冀";
      } else if (this.prov == "山西") {
        fName = "晋";
      } else if (this.prov == "辽宁") {
        fName = "辽";
      } else if (this.prov == "吉林") {
        fName = "吉";
      } else if (this.prov == "黑龙江") {
        fName = "黑";
      } else if (this.prov == "江苏") {
        fName = "苏";
      } else if (this.prov == "浙江") {
        fName = "浙";
      } else if (this.prov == "安徽") {
        fName = "皖";
      } else if (this.prov == "福建") {
        fName = "闽";
      } else if (this.prov == "江西") {
        fName = "赣";
      } else if (this.prov == "山东") {
        fName = "鲁";
      } else if (this.prov == "河南") {
        fName = "豫";
      } else if (this.prov == "湖北") {
        fName = "鄂";
      } else if (this.prov == "湖南") {
        fName = "湘";
      } else if (this.prov == "广东") {
        fName = "粤";
      } else if (this.prov == "海南") {
        fName = "琼";
      } else if (this.prov == "四川") {
        fName = "川";
      } else if (this.prov == "贵州") {
        fName = "黔";
      } else if (this.prov == "云南") {
        fName = "云/滇";
      } else if (this.prov == "陕西") {
        fName = "陕";
      } else if (this.prov == "甘肃") {
        fName = "甘";
      } else if (this.prov == "青海") {
        fName = "青";
      } else if (this.prov == "台湾") {
        fName = "台";
      } else if (this.prov == "内蒙古") {
        fName = "蒙";
      } else if (this.prov == "广西") {
        fName = "桂";
      } else if (this.prov == "宁夏") {
        fName = "宁";
      } else if (this.prov == "新疆 ") {
        fName = "新";
      } else if (this.prov == "西藏") {
        fName = "藏";
      } else if (this.prov == "香港特别行政区") {
        fName = "港";
      } else if (this.prov == "澳门特别行政区") {
        fName = "澳"; 
      }
      this.setData({
        firstName: fName
      })
      
    },
    // 按时间 姓名 公司
    tapMainMenu: function (e) {     // 获取当前显示的一级菜单标识
      this.setData({
        searchMain: true,
        chooseCondition: !this.data.chooseCondition
      })
    },
    // 搜索
    tapSearch: function() {
      this.setData({
        topMain: false,
        Search: true,
        searchMain: false,
        chooseCondition: false
      })
    },
    // 取消搜索
    hideTopSearch: function() {
      this.setData({
        Search: false,
        topMain: true,
        searchMain: true
      })
    },

    //搜索框聚焦
    keyFocus: function() {
      this.setData({
        showKeyDel: "block"
      });
    },

    //搜索框失焦
    keyBlur: function() {
      this.setData({
        showKeyDel: "none"
      });
    },

    //搜索框触发事件
    changeKey: function(e) {
      var value = e.detail.value;
      this.setData({
        keyValue: value
      });
      //开始触发搜索条件
      var tempList = new Array();
      var originalList = this.data.parentList;
      if (value) {
        for (var item in originalList) {
          if (originalList[item].userName.indexOf(value) != -1) {
            tempList.push(originalList[item]);
          }
        }
      }

      this.setData({
        searchBusInfoList: tempList
      });
    },

    //清除搜索框事件
    delKeyTap: function() {
      this.setData({
        keyValue: "",
        searchBusInfoList: new Array()
      });
    },

    // 搜索条件  姓名 时间 公司
    chooseCondition: function(e) {
      var tempList = this.data.selectConditionList;
      var index = e.currentTarget.dataset.key;
      tempList.forEach(function (e) {
        e.slt = false;
      });
      tempList[index].slt = true;
      //开始运用过滤条件
      if (tempList[index].name === '90#') {
        this.sortByname();
      } else if (tempList[index].name === '93#') {
        this.sortByTime();
      } else if (tempList[index].name === '95#') {
        this.sortByCompany();
      } else if (tempList[index].name === '97#') {
        this.sortByCompany();
      }

      this.setData({
        chooseCondition: false,
        selectConditionList: tempList,
        tipmsg: tempList[index].name,
        tipmsgImg: tempList[index].img
      });
    },

    //按姓名进行排序
    sortByname: function() {
      
    },

    // 按时间进行排序
    sortByTime: function() {
      var tempList = this.data.parentList;
      var map = {},dest = [];
      for (var i = 0; i < tempList.length; i++) {
        var ai = tempList[i];
        if (!map[ai.time]) {
          dest.push({
            initial: ai.time,
            busInfoList: [ai]
          });
          map[ai.time] = ai;
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j];
            if (dj.initial == ai.time) {
              dj.busInfoList.push(ai);
              break;
            }
          }
        }
      }
      // console.log(dest);
      this.setData({
        bussinessInfoList: dest
      });
    },

    // 按公司名称进行排序
    sortByCompany: function () {
      var tempList = this.data.parentList;
      var map = {},
        dest = [];
      for (var i = 0; i < tempList.length; i++) {
        var ai = tempList[i];
        if (!map[ai.company]) {
          dest.push({
            initial: ai.company,
            busInfoList: [ai]
          });
          map[ai.company] = ai;
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j];
            if (dj.initial == ai.company) {
              dj.busInfoList.push(ai);
              break;
            }
          }
        }
      }
      // console.log(dest);
      this.setData({
        bussinessInfoList: dest
      });
    },

    goIndex: function() {
      wx.switchTab({
        url: '../index/index'
      })
    },

    goCall: function(e) {
      var iPhone = e.target.id
      wx.makePhoneCall({
        phoneNumber: iPhone
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
      
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
      wx.stopPullDownRefresh();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    }

    /**
     * 用户点击右上角分享
     */
    // onShareAppMessage: function () {

    // }
  })